package com.hnhs.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hnhs.entity.UserQuery;
import com.hnhs.entity.Userd;
import com.hnhs.service.IUserdService;
import com.hnhs.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api")
public class UserPageController {

    @Autowired
    private IUserdService service;

    @GetMapping("/findByUser")
    public Object getAllUser(UserQuery userQuery){
        Page<Userd> page=new Page<>(
                userQuery.getPageNum(),
                userQuery.getPageSize());
        QueryWrapper<Userd> wrapper=new QueryWrapper<>();

            if (userQuery.getUsername() != null && !userQuery.getUsername().equals("")) {
                wrapper.like("username", userQuery.getUsername());
            }
            if (userQuery.getRoleId() != null) {
                wrapper.eq("roleId", userQuery.getRoleId());
            }

            Page<Userd> page1 = service.page(page, wrapper);

            return ResultUtil.success("查询成功", page1);

    }
}
